#
# Copyright 2021-2025 Software Radio Systems Limited
#
# This file is part of srsRAN
#
# srsRAN is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# srsRAN is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# A copy of the GNU Affero General Public License can be found in
# the LICENSE file in the top-level directory of this distribution
# and at http://www.gnu.org/licenses/.
#

# Add a custom empty target that will have all vector-based tests as dependencies.
add_custom_target(all_vector_tests)

# Adds a vector-based test.
#
# Adds a test for TARGET to be run by ctest that uses input and output data generated by an external tool. The test is
# labeled as vectortest.
#
# It optionally uses the vectors contained in VECTOR_FILE (this is a tar.gz file containing all vectors in the
# appropriate format, which will be extracted in the proper build directory). Set VECTOR_FILE to none if no external
# test vector files are required.
#
# Other arguments to the underlying add_test command can be provided through TEST_ARGS.
macro(ADD_TEST_VECTOR TARGET VECTOR_FILE TEST_ARGS)
    if (NOT (${VECTOR_FILE} STREQUAL none))
        if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${VECTOR_FILE})
            file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test_data)
            add_custom_command(
                    TARGET ${TARGET}
                    POST_BUILD
                    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test_data
                    COMMAND ${CMAKE_COMMAND} -E tar xf ${CMAKE_CURRENT_SOURCE_DIR}/${VECTOR_FILE}
                    VERBATIM)
        else (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${VECTOR_FILE})
            message(FATAL_ERROR "Vector file ${CMAKE_CURRENT_SOURCE_DIR}/${VECTOR_FILE} does not exist.")
        endif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${VECTOR_FILE})
    endif (NOT (${VECTOR_FILE} STREQUAL none))
    add_test(${TARGET} ${TARGET} ${TEST_ARGS})
    set_property(TEST ${TARGET} APPEND PROPERTY LABELS vectortest)
    # Add the target to the "all_vector_tests" target.
    add_dependencies(all_vector_tests ${TARGET})
endmacro(ADD_TEST_VECTOR TARGET VECTOR_FILE ...)

add_subdirectory(adt)
add_subdirectory(apps)
add_subdirectory(asn1)
add_subdirectory(cu_cp)
add_subdirectory(cu_up)
add_subdirectory(du_manager)
add_subdirectory(e1ap)
add_subdirectory(e2)
add_subdirectory(f1ap)
add_subdirectory(f1u)
add_subdirectory(fapi)
add_subdirectory(fapi_adaptor)
add_subdirectory(gateways)
add_subdirectory(gtpu)
add_subdirectory(mac)
add_subdirectory(ngap)
add_subdirectory(nru)
add_subdirectory(ofh)
add_subdirectory(pcap)
add_subdirectory(pdcp)
add_subdirectory(phy)
add_subdirectory(radio)
add_subdirectory(ran)
add_subdirectory(rlc)
add_subdirectory(rrc)
add_subdirectory(scheduler)
add_subdirectory(sdap)
add_subdirectory(security)
add_subdirectory(srslog)
add_subdirectory(srsvec)
add_subdirectory(support)
